# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Philipp Sieweck

pkgname=cvc4
pkgver=1.8
pkgrel=2
pkgdesc="An automatic theorem prover"
arch=('loong64' 'x86_64')
url="https://cvc4.github.io/"
depends=('boost-libs' 'libantlr3c' 'cln')
makedepends=('boost' 'cmake' 'java-runtime' 'python-toml')
optdepends=('readline: for an improved interaction support')
license=('GPL' 'BSD' 'MIT' 'custom:HPND')
source=("https://github.com/CVC4/CVC4/archive/$pkgver/$pkgname-$pkgver.tar.gz"
        "https://www.antlr3.org/download/antlr-3.4-complete.jar"
        cvc4-fix-headers.patch
        cvc4-gcc7.patch)
noextract=('antlr-3.4-complete.jar')
sha512sums=('19e318a62f0a6dfeea4db5225b150550f1e7afcf42a3547bad1ff2030aca7a7713fe29e7059f2dc391eaa18b0cd4183f99ab2dca5008979cb8881b46b8dc01f2'
            '04be4dfba3a21f3ab9d9e439a64958bd8e844a9f151b798383bd9e0dd6ebc416783ae7cb1d1dbb27fb7288ab9756b13b8338cdb8ceb41a10949c852ad45ab1f2'
            'f6a60c2b95c348f7e8abffc79befef0910ff962143b0b5f89f9b3c9798fff575a9bfc71ae8271c9e56e2f5e400539879b440df23aef7c23664eaec9cd5d6fe10'
            'ff5d60141f97394b625c336614afa5a6429d775bed12e277ad1bc64b84f865a958fb075185fb9726ea8ca443b55aedb1a8d114840f016ed8e639dbcf77aa3783')

prepare() {
  cd "$srcdir/CVC4-$pkgver"

  patch -p1 -i ../cvc4-fix-headers.patch
  patch -p1 -i ../cvc4-gcc7.patch

  mkdir -p antlr-3.4/bin
  tee antlr-3.4/bin/antlr3 <<EOF
#!/bin/bash
export CLASSPATH=$srcdir/antlr-3.4-complete.jar:\$CLASSPATH
exec java org.antlr.Tool "\$@"
EOF
  chmod a+x antlr-3.4/bin/antlr3
}

build() {
  cd "$srcdir/CVC4-$pkgver"
  export PATH="$PATH:$PWD/antlr-3.4/bin"
  ./configure.sh --prefix=/usr --cln --gpl
  cd build
  make
}

check() {
  cd "$srcdir/CVC4-$pkgver/build"
  make check
}

package() {
  cd "$srcdir/CVC4-$pkgver/build"
  make DESTDIR="$pkgdir/" install
  install -Dm644 "$srcdir/CVC4-$pkgver/COPYING" "$pkgdir"/usr/share/licenses/cvc4/LICENSE
}
